package snsdbook.servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import snsdbook.engine.PaginatedContentList;
import util.SQLUtil;
import util.Util;

/**
 * Servlet implementation class MyContentsServlet
 */
public class MyContentsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MyContentsServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	  String username = request.getParameter("username");
	  String[] ids = SQLUtil.Query(
	      "SELECT id_berita FROM berita WHERE username='" + username + "' ORDER BY waktu DESC");
	  int page = 0;
    if (request.getParameterMap().containsKey("page")) {
      page = Integer.valueOf(request.getParameter("page"));
    }
    PaginatedContentList.Display(
        Util.toArrayInt(ids),
        /* show_searchbar =  */ false,
        /* show_comments = */ false,
        /* show_pagination = */ true,
        /* is_short = */ true,
        /* page = */ page,
        request,
        response);
	}

}
